WPS Office.apk(点击下载) / GifTextureView.java


package pl.droidsonroids.gif;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Surface;
import android.view.TextureView;
import android.widget.ImageView;
import defpackage.abpc;
import defpackage.abpd;
import java.io.IOException;
import java.lang.ref.WeakReference;

public class GifTextureView extends TextureView {
    private static final ImageView.ScaleType[] CZL = {ImageView.ScaleType.MATRIX, ImageView.ScaleType.FIT_XY, ImageView.ScaleType.FIT_START, ImageView.ScaleType.FIT_CENTER, ImageView.ScaleType.FIT_END, ImageView.ScaleType.CENTER, ImageView.ScaleType.CENTER_CROP, ImageView.ScaleType.CENTER_INSIDE};
    private abpc.b CZK;
    private final Matrix CZM = new Matrix();
    private b CZN;
    private float CZO = 1.0f;
    private abpd CZe;
    private ImageView.ScaleType dYN = ImageView.ScaleType.FIT_CENTER;

    /* access modifiers changed from: package-private */
    /* renamed from: pl.droidsonroids.gif.GifTextureView$1  reason: invalid class name */
    public static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] edw = new int[ImageView.ScaleType.values().length];

        static {
            try {
                edw[ImageView.ScaleType.CENTER.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                edw[ImageView.ScaleType.CENTER_CROP.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                edw[ImageView.ScaleType.CENTER_INSIDE.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                edw[ImageView.ScaleType.FIT_CENTER.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
            try {
                edw[ImageView.ScaleType.FIT_END.ordinal()] = 5;
            } catch (NoSuchFieldError e5) {
            }
            try {
                edw[ImageView.ScaleType.FIT_START.ordinal()] = 6;
            } catch (NoSuchFieldError e6) {
            }
            try {
                edw[ImageView.ScaleType.FIT_XY.ordinal()] = 7;
            } catch (NoSuchFieldError e7) {
            }
            try {
                edw[ImageView.ScaleType.MATRIX.ordinal()] = 8;
            } catch (NoSuchFieldError e8) {
            }
        }
    }

    public interface a {
    }

    /* access modifiers changed from: package-private */
    public static class b extends Thread implements TextureView.SurfaceTextureListener {
        final abov CZP = new abov();
        private GifInfoHandle CZQ = new GifInfoHandle();
        long[] CZR;
        private final WeakReference<GifTextureView> CZS;
        private IOException ubO;

        b(GifTextureView gifTextureView) {
            super("GifRenderThread");
            this.CZS = new WeakReference<>(gifTextureView);
        }

        /* access modifiers changed from: package-private */
        public final void a(GifTextureView gifTextureView, a aVar) {
            this.CZP.close();
            GifTextureView.super.setSurfaceTextureListener(aVar != null ? new abpg(aVar) : null);
            this.CZQ.hgS();
            interrupt();
        }

        public final void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
            GifTextureView gifTextureView = this.CZS.get();
            if (gifTextureView != null) {
                gifTextureView.a((GifTextureView) this.CZQ);
            }
            this.CZP.open();
        }

        public final boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
            this.CZP.close();
            this.CZQ.hgS();
            interrupt();
            return true;
        }

        public final void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) {
        }

        public final void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
        }

        public final void run() {
            try {
                GifTextureView gifTextureView = this.CZS.get();
                if (gifTextureView != null) {
                    this.CZQ = gifTextureView.CZe.hgW();
                    this.CZQ.d((char) 1, gifTextureView.isOpaque());
                    if (gifTextureView.CZK.uCC >= 0) {
                        this.CZQ.apJ(gifTextureView.CZK.uCC);
                    }
                    final GifTextureView gifTextureView2 = this.CZS.get();
                    if (gifTextureView2 == null) {
                        this.CZQ.recycle();
                        return;
                    }
                    GifTextureView.super.setSurfaceTextureListener(this);
                    boolean isAvailable = gifTextureView2.isAvailable();
                    this.CZP.set(isAvailable);
                    if (isAvailable) {
                        gifTextureView2.post(new Runnable() {
                            /* class pl.droidsonroids.gif.GifTextureView.b.AnonymousClass1 */

                            public final void run() {
                                gifTextureView2.a((GifTextureView) b.this.CZQ);
                            }
                        });
                    }
                    this.CZQ.hT(gifTextureView2.CZO);
                    while (!isInterrupted()) {
                        try {
                            this.CZP.block();
                            SurfaceTexture surfaceTexture = gifTextureView2.getSurfaceTexture();
                            if (surfaceTexture != null) {
                                Surface surface = new Surface(surfaceTexture);
                                try {
                                    GifInfoHandle gifInfoHandle = this.CZQ;
                                    GifInfoHandle.bindSurface(gifInfoHandle.CZG, surface, this.CZR);
                                } finally {
                                    surface.release();
                                }
                            }
                        } catch (InterruptedException e) {
                            Thread.currentThread().interrupt();
                        }
                    }
                    this.CZQ.recycle();
                    this.CZQ = new GifInfoHandle();
                }
            } catch (IOException e2) {
                this.ubO = e2;
            }
        }
    }

    public GifTextureView(Context context) {
        super(context);
        a(null, 0, 0);
    }

    public GifTextureView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        a(attributeSet, 0, 0);
    }

    public GifTextureView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        a(attributeSet, i, 0);
    }

    public GifTextureView(Context context, AttributeSet attributeSet, int i, int i2) {
        super(context, attributeSet, i, i2);
        a(attributeSet, i, i2);
    }

    private void a(AttributeSet attributeSet, int i, int i2) {
        abpd aVar;
        if (attributeSet != null) {
            int attributeIntValue = attributeSet.getAttributeIntValue("http://schemas.android.com/apk/res/android", "scaleType", -1);
            if (attributeIntValue >= 0 && attributeIntValue < CZL.length) {
                this.dYN = CZL[attributeIntValue];
            }
            TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, R.styleable.GifTextureView, i, i2);
            TypedValue typedValue = new TypedValue();
            if (!obtainStyledAttributes.getValue(R.styleable.GifTextureView_gifSource, typedValue)) {
                aVar = null;
            } else {
                if (typedValue.resourceId != 0) {
                    String resourceTypeName = obtainStyledAttributes.getResources().getResourceTypeName(typedValue.resourceId);
                    if (abpc.CZW.contains(resourceTypeName)) {
                        aVar = new abpd.c(obtainStyledAttributes.getResources(), typedValue.resourceId);
                    } else if (!"string".equals(resourceTypeName)) {
                        throw new IllegalArgumentException("Expected string, drawable, mipmap or raw resource type. '" + resourceTypeName + "' is not supported");
                    }
                }
                aVar = new abpd.a(obtainStyledAttributes.getResources().getAssets(), typedValue.string.toString());
            }
            this.CZe = aVar;
            super.setOpaque(obtainStyledAttributes.getBoolean(R.styleable.GifTextureView_isOpaque, false));
            obtainStyledAttributes.recycle();
            this.CZK = new abpc.b(this, attributeSet, i, i2);
        } else {
            super.setOpaque(false);
            this.CZK = new abpc.b();
        }
        if (!isInEditMode()) {
            this.CZN = new b(this);
            if (this.CZe != null) {
                this.CZN.start();
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void a(GifInfoHandle gifInfoHandle) {
        float f = 1.0f;
        Matrix matrix = new Matrix();
        float width = (float) getWidth();
        float height = (float) getHeight();
        float width2 = ((float) gifInfoHandle.getWidth()) / width;
        float height2 = ((float) gifInfoHandle.getHeight()) / height;
        RectF rectF = new RectF(0.0f, 0.0f, (float) gifInfoHandle.getWidth(), (float) gifInfoHandle.getHeight());
        RectF rectF2 = new RectF(0.0f, 0.0f, width, height);
        switch (AnonymousClass1.edw[this.dYN.ordinal()]) {
            case 1:
                matrix.setScale(width2, height2, width / 2.0f, height / 2.0f);
                break;
            case 2:
                float min = 1.0f / Math.min(width2, height2);
                matrix.setScale(width2 * min, min * height2, width / 2.0f, height / 2.0f);
                break;
            case 3:
                if (((float) gifInfoHandle.getWidth()) > width || ((float) gifInfoHandle.getHeight()) > height) {
                    f = Math.min(1.0f / width2, 1.0f / height2);
                }
                matrix.setScale(width2 * f, f * height2, width / 2.0f, height / 2.0f);
                break;
            case 4:
                matrix.setRectToRect(rectF, rectF2, Matrix.ScaleToFit.CENTER);
                matrix.preScale(width2, height2);
                break;
            case 5:
                matrix.setRectToRect(rectF, rectF2, Matrix.ScaleToFit.END);
                matrix.preScale(width2, height2);
                break;
            case 6:
                matrix.setRectToRect(rectF, rectF2, Matrix.ScaleToFit.START);
                matrix.preScale(width2, height2);
                break;
            case 7:
                return;
            case 8:
                matrix.set(this.CZM);
                matrix.preScale(width2, height2);
                break;
        }
        super.setTransform(matrix);
    }

    public TextureView.SurfaceTextureListener getSurfaceTextureListener() {
        return null;
    }

    public Matrix getTransform(Matrix matrix) {
        if (matrix == null) {
            matrix = new Matrix();
        }
        matrix.set(this.CZM);
        return matrix;
    }

    /* access modifiers changed from: protected */
    public void onDetachedFromWindow() {
        this.CZN.a(this, null);
        super.onDetachedFromWindow();
        SurfaceTexture surfaceTexture = getSurfaceTexture();
        if (surfaceTexture != null) {
            surfaceTexture.release();
        }
    }

    public void onRestoreInstanceState(Parcelable parcelable) {
        if (!(parcelable instanceof GifViewSavedState)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        GifViewSavedState gifViewSavedState = (GifViewSavedState) parcelable;
        super.onRestoreInstanceState(gifViewSavedState.getSuperState());
        this.CZN.CZR = gifViewSavedState.CZV[0];
    }

    public Parcelable onSaveInstanceState() {
        this.CZN.CZR = this.CZN.CZQ.hgT();
        return new GifViewSavedState(super.onSaveInstanceState(), this.CZK.CZY ? this.CZN.CZR : null);
    }

    public void setFreezesAnimation(boolean z) {
        this.CZK.CZY = z;
    }

    public void setImageMatrix(Matrix matrix) {
        setTransform(matrix);
    }

    public synchronized void setInputSource(abpd abpd) {
        setInputSource(abpd, null);
    }

    public synchronized void setInputSource(abpd abpd, a aVar) {
        this.CZN.a(this, aVar);
        try {
            this.CZN.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.CZe = abpd;
        this.CZN = new b(this);
        if (abpd != null) {
            this.CZN.start();
        }
    }

    public void setOpaque(boolean z) {
        if (z != isOpaque()) {
            super.setOpaque(z);
            setInputSource(this.CZe);
        }
    }

    public void setScaleType(ImageView.ScaleType scaleType) {
        this.dYN = scaleType;
        a(this.CZN.CZQ);
    }

    public void setSpeed(float f) {
        this.CZO = f;
        this.CZN.CZQ.hT(f);
    }

    public void setSurfaceTexture(SurfaceTexture surfaceTexture) {
        throw new UnsupportedOperationException("Changing SurfaceTexture is not supported");
    }

    public void setSurfaceTextureListener(TextureView.SurfaceTextureListener surfaceTextureListener) {
        throw new UnsupportedOperationException("Changing SurfaceTextureListener is not supported");
    }

    public void setTransform(Matrix matrix) {
        this.CZM.set(matrix);
        a(this.CZN.CZQ);
    }
}